#include <bwio.h>
#include <ts7200.h>
#include <user.h>
#include <defs.h>

void NameServer();

void RegisterTest1() {
  int reply;
  bwprintf(COM2, "Registering TID 2 as TesterOne.\r\n");
  reply = RegisterAs("TesterOne");
  bwprintf(COM2, "Answer is %d.\r\n", reply);
  Exit();
}

void RegisterTest2() {
  int reply;
  bwprintf(COM2, "Who is Onko?\r\n");
  reply = WhoIs("Onko");
  bwprintf(COM2, "Answer is %d.\r\n", reply);
  bwprintf(COM2, "Registering TID 3 as TesterTwo.\r\n");
  reply = RegisterAs("TesterTwo");
  bwprintf(COM2, "Answer is %d.\r\n", reply);
  bwprintf(COM2, "Who is TesterTwo?\r\n");
  reply = WhoIs("TesterTwo");
  bwprintf(COM2, "Answer is %d.\r\n", reply);
  bwprintf(COM2, "Who is TesterOne?\r\n");
  reply = WhoIs("TesterOne");
  bwprintf(COM2, "Answer is %d.\r\n", reply);
  bwprintf(COM2, "Registering TID 3 as TesterOne.\r\n");
  reply = RegisterAs("TesterOne");
  bwprintf(COM2, "Answer is %d.\r\n", reply);
  bwprintf(COM2, "Who is TesterOne?\r\n");
  reply = WhoIs("TesterOne");
  bwprintf(COM2, "Answer is %d.\r\n", reply);
  Exit();
}

void UserInit() {
  int child;
  child = Create( 3, &NameServer );
  Send(child, NULL, 0, NULL, 0);
  bwprintf( COM2, "Created NameServer (TID=1): %d\r\n", child );
  child = Create( 1, &RegisterTest1 );
  bwprintf( COM2, "Created: %d\r\n", child );
  child = Create( 0, &RegisterTest2 );
  bwprintf( COM2, "Created: %d\r\n", child );
  bwprintf( COM2, "First: exiting\r\n" );
  Exit();
}
